package com.xonro.common.histrans.zz.biz.base;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.util.UUIDGener;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.consts.DrpConst;
import com.xonro.common.histrans.base.ctx.BOCreateData;
import com.xonro.common.histrans.base.ctx.FileTransData;
import com.xonro.common.histrans.base.ctx.HistoryTransContext;
import com.xonro.common.histrans.base.model.HistoryTransLogModel;

import com.xonro.common.histrans.zz.biz.common.DrpProcessTransBiz;
import com.xonro.common.histrans.zz.ctx.DrpProcessCreateContext;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class ProcessProjectIntroducerBiz extends DrpProcessTransBiz {
    @Override
    protected void transProcess0(DrpProcessCreateContext historyTransContext) {
        String createUser = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getCreateUser();
        String bindId = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getId();
        Timestamp startTime = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getStartTime();
        List<BOCreateData> boCreateDataList = new ArrayList<>();
        RowMap mainData = historyTransContext.getMainData();
        SDK.getLogAPI().consoleInfo("获取项目介绍人数据");

        //添加日志
        String mainBOId = UUIDGener.getUUID();
        HistoryTransLogModel logModel = new HistoryTransLogModel();
        historyTransContext.setHistoryTransLogModel(logModel);
        logModel.setBindId(bindId);
        logModel.setBpmBOId(mainBOId);
        logModel.setBpmTable("BO_EU_PROJECT_INTRODUCER_APPLY");//项目介绍人
        logModel.setOuterTable("ct_ProjectIntroducers");//项目介绍人
        logModel.setOuterPK(mainData.getString("MyId"));
        logModel.setOuterExt1(mainData.getString("JobNo"));//工号
        logModel.setOuterExt2(mainData.getString("BillNo"));//单据号
        BOCreateData mainBOCreateData = new BOCreateData();
        boCreateDataList.add(mainBOCreateData);
        BO mainBO = new BO();
        mainBOCreateData.setBoName("BO_EU_PROJECT_INTRODUCER_APPLY");
        mainBOCreateData.setBo(mainBO);
        mainBOCreateData.setCreateUser(createUser);
        mainBO.setCreateDate(startTime);
        mainBO.setUpdateDate(startTime);
        mainBO.setId(mainBOId);
        mainBO.set("DATA_TYPE","2");//历史数据
        mainBO.set("DRP_ID",mainData.getString("MyId"));
        mainBO.set("APPLY_NO",mainData.getString("BillNo"));
        mainBO.set("APPLY_DATE",mainData.getString("CreateTime"));
        mainBO.set("APPLY_USER",mainData.getString("CreateName"));
        mainBO.set("APPLY_USER_ID",mainData.getString("CreateId"));
        mainBO.set("APPLY_DEPT",mainData.getString("CreateDept"));
        mainBO.set("APPLY_DEPT_ID",mainData.getString("CreateDeptId"));
        mainBO.set("PROCESS_STATUS",mainData.getString("ProcInstState"));
        mainBO.set("BU_CENTER",mainData.getString("MarketingUnit"));
        mainBO.set("BU_UNIT","");

        mainBO.set("STATUS","");
        mainBO.set("YEAR","");
        mainBO.set("MONTH","");
        mainBO.set("USER_NAME",mainData.getString("Name"));
        mainBO.set("SEX",mainData.getString("Sex"));
        mainBO.set("CARD_TYPE",mainData.getString("DocumentType"));
        mainBO.set("ID_CARD",mainData.getString("IDNumber"));
        mainBO.set("PHONE_1",mainData.getString("TelephoneOne"));
        mainBO.set("PHONE_2",mainData.getString("TelephoneTwo"));
        mainBO.set("CITY",mainData.getString("FixedCity"));
        mainBO.set("DETAIL_ADDRESS",mainData.getString("ActualAddress"));
        mainBO.set("ADDRESS",mainData.getString("ActualAddress"));
        mainBO.set("WARN_RANGE","");
        mainBO.set("GRADE",mainData.getString("ProjectIntroducerLevel"));
        mainBO.set("P_STATUS",mainData.getString("ProjectIntroducersStatus"));
        historyTransContext.getProcessCreateContext().setBoCreateDatas(boCreateDataList);
        FileTransData fileTransData = new FileTransData();
        fileTransData.setBoId(mainBOId);
        //OA表订单编号
        //   fileTransData.setFkCode(mainData.getString("xmbh"));
        fileTransData.setFileJson(mainData.getString("File"));
        fileTransData.setProcessInstId(bindId);
        historyTransContext.getFileTransDatas().add(fileTransData);
        fileTransData.setBoName("BO_EU_PROJECT_INTRODUCER_APPLY");
        fileTransData.setFieldName("FJ");
        // fileTransData.setUserId(mainData.getString("CreateId"));//编制人Id
        fileTransData.setUserId("admin");
        fileTransData.setAppId("com.awspaas.user.apps.zhongzhuang.mis");
        fileTransData.setCreateDate(new Timestamp(mainData.getDate("CreateTime").getTime()));
    }
    @Override
    protected List<RowMap> getMainDatas() {
        return SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMaps("SELECT * FROM ct_ProjectIntroducers limit 50");
    }

    @Override
    protected RowMap getMainData() {
        return null;
    }


    @Override
    protected String getDrpType() {
        return null;
    }

    @Override
    protected String getProcessDefId() {
        return "obj_1c5672f2027d4cd58b413f1bbafc15e8";
    }

    @Override
    protected String getActivityDefId() {
        return "obj_2f96ce1c064940c087b60cab895ebe1d";
    }

    @Override
    protected String getTitle(HistoryTransContext ctx) {
        String billNo = ctx.getMainData().getString("BillNo");//单据号
        return "项目介绍人登记申请流程历史数据同步"+billNo;
    }

    @Override
    protected String getEnCode(HistoryTransContext ctx) {
        RowMap mainData = ctx.getMainData();
        return mainData.getString("Wiid");
    }




    @Override
    protected String getOuterTable(DrpProcessCreateContext historyTransContext) {
        return "ct_ProjectIntroducers";
    }

    @Override
    protected String getPk(DrpProcessCreateContext historyTransContext) {
        RowMap mainData = historyTransContext.getMainData();
        return mainData.getString("MyId");
    }
}
